/**
 * @file       DigitChar.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 12, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "DigitChar.h"
#include "errorcode.h"

namespace NS_LCD_AFW
{

CDigitChar::CDigitChar()
{
	setChar(' ');
	this->setFocusable(true);
	this->setHightlightable(true);
}

CDigitChar::~CDigitChar()
{
}

void CDigitChar::setChar(char c)
{
	if (c == ' ' || (c >= '0' && c <= '9') || '.' == c)
	{
		CChar::setChar(c);
	}

	if ('.' == c)
	{
		this->setFocusable(false);
		this->setHightlightable(false);
	}
}

int CDigitChar::onUpKeyPress()
{
	switch (m_cChar)
	{
	case ' ':
		m_cChar = '0';
		break;
	case '9':
		m_cChar = ' ';
		break;
	default:
		++m_cChar;
		break;
	}
	return this->invalidate();
}

int CDigitChar::onDownKeyPress()
{
	switch (m_cChar)
	{
	case ' ':
		m_cChar = '9';
		break;
	case '0':
		m_cChar = ' ';
		break;
	default:
		--m_cChar;
		break;
	}
	return this->invalidate();
}

} /* namespace NS_LCD_AFW */
